<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<c:url value='/css/estilos.css'/>"/>
<title>Adicionar persona</title>

<script type="text/javascript">

 function validations(){
	 
	 if(""==document.forms.personForm.name.value  || ""==document.forms.personForm.userCode.value || ""==document.forms.personForm.password.value
			 || ""==document.forms.personForm.userType.value){
		 alert("todos los campos son requeridos");
		 return false;
	 }
	 
	 return true;
 }

</script>

</head>
<body>
<header> <jsp:include page="items.jsp"></jsp:include> </header>

<h1>Crear nueva persona</h1>

<c:url var="saveUrl" value="/main/persons/add" />
<form:form name="personForm" modelAttribute="personAttribute" method="POST" action="${saveUrl}" onsubmit="return validations();">
	<table>
		<tr>
			<td><form:label path="name">Nombre:</form:label></td>
			<td><form:input path="name" id="name"/></td>
		</tr>
		<tr>
			<td><form:label path="userCode">Usuario:</form:label></td>
			<td><form:input path="userCode" id="userCode"/></td>
		</tr>
		
		<tr>
			<td><form:label path="password">Contraseña:</form:label></td>
			<td><form:input path="password" id="password"/></td>
		</tr>
		
				<tr>
			<td><form:label path="userType">Tipo de Usuario:</form:label></td>
			<td><form:select path="userType" id="userType">
			<form:options items="${userTypeList}" itemLabel="name" itemValue="code" />
			</form:select>
			</td>
		</tr>
	</table>
	
	<input type="submit" value="Guardar" />
</form:form>

</body>
</html>